﻿#region Copyright Notice
// This file is part of GestionPedago.
// <description>
// Copyright (C) 2012 ENI Ecole Informatique
// 
// GestionPedago is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// <program> is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using GestionPedago.EntityContext;
using GestionPedago.Services.Framework;
using GestionPedago.Services.ES.Modele;
using GestionPedago.Persistence.OPManager;

namespace GestionPedago.Services.Mapping
{
    /// <summary>
    /// Classe de mapping Entity<->ES de l'objet ModuleParECF
    /// </summary>
    public class ModuleParECFMappeur : IMappeur<ModuleParECF, ModuleParECFES>
    {
        /// <summary>
        /// Constructeur
        /// </summary>
        public ModuleParECFMappeur() { }

        /// <summary>
        /// Mapping Entity -> ES
        /// </summary>
        /// <param name="entity">L'entity � mapper</param>
        /// <returns>L'ES obtenu</returns>
        public ModuleParECFES Entity2ES(ModuleParECF entity)
        {
            ModuleParECFES retour = new ModuleParECFES();
            retour.IdModuleParECF = entity.IdModuleParECF;
            retour.IdModule = entity.IdModule;
            retour.IdECF = entity.IdECF;
         /*   retour.ECF = new ECFMappeur().Entity2ES(entity.ECF);
            retour.Module = new ModuleMappeur().Entity2ES(entity.Module);*/
           /* if (!EntityStateChecker.IsDetached(entity))
            {
                EntityConnection.GetContext().Detach(entity);
            }*/
            return retour;
        }

        /// <summary>
        /// Mapping ES -> Entity
        /// </summary>
        /// <param name="es">L'ES � mapper</param>
        /// <returns>L'entity obtenu</returns>
        public ModuleParECF ES2Entity(ModuleParECFES es)
        {
            ModuleParECF retour = new ModuleParECF();
            retour.IdModuleParECF = es.IdModuleParECF;
            bool alreadyAttached = !EntityStateChecker.IsDetached(retour);
            if (!alreadyAttached)
            {
                EntityConnection.GetContext().ModuleParECF.Attach(retour);
            }
            retour.IdModule = es.IdModule;
            retour.IdECF = es.IdECF;
         /*   retour.ECF = new ECFMappeur().ES2Entity(es.ECF);
            retour.Module = new ModuleMappeur().ES2Entity(es.Module);*/
            if (alreadyAttached)
            {
                EntityConnection.GetContext().ModuleParECF.ApplyCurrentValues(retour);
            }
            return retour;
        }
    }
}
